<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="system" tagdir="/WEB-INF/tags/system"%>
<probiz:pageHeading pageHeadingKey="orderShipList.heading" />

<content tag="buttons">
   <probiz:iconBtn btnType="print" btnTextKey="orderShipList.button.print" onclick="printShipList();" />
   <probiz:iconBtn btnType="print" btnTextKey="orderShipList.button.printExpress" onclick="printExpress();" />
   <c:if test="${not empty orderShipmentList}">
   		<probiz:iconBtn btnType="saveTrackingNo" btnTextKey="orderShipList.button.saveTrackingNo" onclick="saveTrackingNo()" />
   </c:if>
</content>

<search:searchBox formAction="${ctxPath}/order/orderShip.html" enableMoreSearch="true">
	<div class="basic_search">
		<search:basicSearch attrPath="os.documentNo" attrNameKey="orderShipment.documentNo" datatype="String"	operator="LIKE" classes="inputtxt" labelWidth="60px"/>
	</div>
	<div class="more_search">
		<table border="0" cellspacing="0" cellpadding="0" class="search_table">
			<search:input attrPath="os.salesOrder.orderNo" attrNameKey="salesOrder.orderNo" datatype="String" operator="LIKE" classes="inputtxt" style="width:150px" labelWidth="60px"/>
			<tr>
				<c:set var="shippingCostGTE">COL@os.shippingCost@BigDecimal@GTE</c:set>
				<c:set var="shippingCostLTE">COL@os.shippingCost@BigDecimal@LTE</c:set>
				<th width="60px"><label for="${shippingCostGTE}"><fmt:message key="orderShipment.shippingCost"/>:</label></th>
				<td>
					<span><input type="text" id="shippingCostGTE" name="${shippingCostGTE}" value="${sc==null?requestScope[shippingCostGTE]:sc.param[shippingCostGTE]}" style="width:61px"  class="inputtxt" validConf="price" onblur="validateEventHandler();"/></span>
					<fmt:message key ="orderPayment.search.to"/>
					<span><input type="text" id="shippingCostLTE" name="${shippingCostLTE}" value="${sc==null?requestScope[shippingCostLTE]:sc.param[shippingCostLTE]}" style="width:61px"  class="inputtxt" validConf="price" onblur="validateEventHandler();"/></span>
				</td>
			</tr>
			<search:input attrPath="os.deliveryTypeDesc" attrNameKey="orderShipment.deliveryTypeDesc" datatype="String" operator="LIKE" classes="inputtxt" style="width:150px" labelWidth="60px"/>
			<tr>
				<c:set var="createTimeGTE">COL@os.createTime@Date_Begin@GTE</c:set>
				<c:set var="createTimeLTE">COL@os.createTime@Date_End@LTE</c:set>
				<th width="60px"><label for="${createTimeGTE}"><fmt:message key="orderShipment.createTime"/>:</label></th>
				<td>
					<span><input type="text" id="createTimeGTE" name="${createTimeGTE}" value="${sc==null?requestScope[createTimeGTE]:sc.param[createTimeGTE]}" style="width:70px"  class="input_readonly" readonly  onblur="validateEventHandler();"/></span>
					<probiz:ui_datePicker outPut="createTimeGTE" />
					<fmt:message key ="orderPayment.search.to"/>
					<span><input type="text" id="createTimeLTE" name="${createTimeLTE}" value="${sc==null?requestScope[createTimeLTE]:sc.param[createTimeLTE]}" style="width:70px"  class="input_readonly" readonly  onblur="validateEventHandler();"/></span>
					<probiz:ui_datePicker outPut="createTimeLTE" />
				</td>
			</tr>
		</table>
	</div>
</search:searchBox>

<form class="mainForm" name="orderShipListForm" method="post" action="${ctxPath}/order/orderShip.html">
	<!--editURLPath is used in TblDecorator-->
	<div class="top clearfix">
		<ul class="tab">
			<li class="curr"><span><fmt:message key="orderShipList.heading"/></span></li>
		</ul>
		<%@include file="/common/pagingOnlyTop.jsp"%>
	</div>
	<div class="data">		
		<c:set var="checkAll">
			<input type="checkbox" name="allbox" onclick="checkAll(this.form)"	class="checkbox" />
		</c:set>
		<c:set var="isNeedTopPaging" value="true"/>
		
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list_table" id="orderShipTable">	
			<tr>
			  	<th width="20"><input onclick="checkAll(this.form)" name="allbox" type="checkbox" value="" /></th>	
				<th style="width:20px;">
					<span class="expand" onclick="toggleScreenAll(this)">&nbsp;</span>
				</th>
				<th style="width:10%" class='sortable ${(sc.param["p-sort"] eq 1)?"sorted order1":((sc.param["p-sort"] eq 2)?"sorted order2":"")}'>		
					<a onclick="sortField(this,1,2)"><fmt:message key="orderShipment.documentNo" /></a>
				</th>
				<th style="width:15%" class='sortable ${(sc.param["p-sort"] eq 3)?"sorted order1":((sc.param["p-sort"] eq 4)?"sorted order2":"")}'>		
					<a onclick="sortField(this,3,4)"><fmt:message key="salesOrder.orderNo" /></a>
				</th>
				<th style="width:15%"  class='sortable ${(sc.param["p-sort"] eq 11)?"sorted order1":((sc.param["p-sort"] eq 12)?"sorted order2":"")}'>	
					<a onclick="sortField(this,11,12)"><fmt:message key="orderShipment.trackingNo" /></a>
				</th>
				<th style="width:10%"  class='sortable ${(sc.param["p-sort"] eq 5)?"sorted order1":((sc.param["p-sort"] eq 6)?"sorted order2":"")}'>		
					<a onclick="sortField(this,5,6)"><fmt:message key="orderShipment.shippingCost" /></a>
				</th>
				<th style="width:15%"  class='sortable ${(sc.param["p-sort"] eq 7)?"sorted order1":((sc.param["p-sort"] eq 8)?"sorted order2":"")}'>		
					<a onclick="sortField(this,7,8)"><fmt:message key="orderShipment.deliveryTypeDesc" /></a>
				</th>
				<th  class='sortable ${(sc.param["p-sort"] eq 9)?"sorted order1":((sc.param["p-sort"] eq 10)?"sorted order2":"")}'>		
					<a onclick="sortField(this,9,10)"><fmt:message key="orderShipment.createTime" /></a>
				</th>
			</tr>
			<c:forEach  items="${orderShipmentList}" var="orderShipment" varStatus="status">
				<tr id="tr${orderShipment.orderShipmentId}" class="${(status.index%2==0)?'even':'odd'}">
					<td>
	    				<input type="checkbox" name="multiIds" value="${orderShipment.orderShipmentId}" title="${orderShipment.documentNo}" class="checkbox" />
					</td>
					<td>
						 <span class="expand toggleScreen" onclick="toggleScreen(this)">&nbsp;</span>                    
					</td>
					<td>
						${orderShipment.documentNo}
					</td>
					<td>
						${orderShipment.salesOrder.orderNo}
					</td>
					<td>
						<input type="hidden" id="orderShipmentId" name="orderShipmentId"	value="${orderShipment.orderShipmentId}"  />
						<input type="text" id="trackingNo${orderShipment.orderShipmentId}" name="trackingNo"	value="${orderShipment.trackingNo}" style="width:150px" class="inputtxt" validConf="maxlength=15" maxlength="15"/>
					</td>
					<td>
						<common:currencyFormat value="${orderShipment.shippingCost}"/>
					</td>
					<td>
						${orderShipment.deliveryTypeDesc}
					</td>
					<td>
						<common:datetimeFormat date="${orderShipment.createTime}" />
					</td>
				</tr>
				<tr style="display: none;" class="${(status.index%2==0)?'even':'odd'}  sub">
					<td></td>
					<td class="consignee" colspan="10">
						<div class="order_show">
							<table cellspacing="0" cellpadding="0" border="0" width="100%">
								<tr>
									<td style="vertical-align:top;width:25%">
										<table cellspacing="0" cellpadding="0" border="0" width="100%" class="consignee_table">
											<tr>
												<th width="100px;"><fmt:message key="orderShipment.documentNo" />:</th>
												<td>${orderShipment.documentNo}</td>
											</tr>
											<tr>
												<th><fmt:message key="orderShipment.deliveryTypeDesc" />:</th>
												<td>${orderShipment.deliveryTypeDesc}</td>
											</tr>
											<c:choose>
												<c:when test="${!orderShipment.isVirtual}">
													<tr>
														<th><fmt:message key="orderShipment.shippingAddress4Ship" />:</th>
														<td>${orderShipment.shippingAddress.regionFullName}<br/>${orderShipment.shippingAddress.address1}</td>
													</tr>
													<tr>
														<th><fmt:message key="salesOrder.shipPanel.firstname" />:</th>
														<td>${orderShipment.shippingAddress.firstname}</td>
													</tr>
													<tr>
														<th><fmt:message key="orderAddress.email" />:</th>
														<td>${orderShipment.shippingAddress.email}</td>
													</tr>
													<tr>
														<th><fmt:message key="orderAddress.phoneNumber" />:</th>
														<td>${orderShipment.shippingAddress.phoneNumber}</td>
													</tr>
													<tr>
														<th><fmt:message key="orderAddress.postalcode" />:</th>
														<td>${orderShipment.shippingAddress.postalcode}</td>
													</tr>
													<tr>
														<th>
															<fmt:message key="salesOrder.deliveryTime"/>:
														</th>
														<td>
															${orderShipment.deliveryTime}
														</td>
													</tr>
													<tr>
														<th>
															<fmt:message key="salesOrder.needConfrimB4Delivery"/>:
														</th>
														<td>
															<fmt:message key="salesOrder.needConfrimB4Delivery.${orderShipment.needConfrimB4Delivery}"/>
														</td>
													</tr>
												</c:when>
												<c:otherwise>
													<tr>
														<th><fmt:message key="salesOrder.shipPanel.firstname" />:</th>
														<td>${orderShipment.shippingAddress.firstname}</td>
													</tr>
													<tr>
														<th><fmt:message key="orderAddress.email" />:</th>
														<td>${orderShipment.shippingAddress.email}</td>
													</tr>
												</c:otherwise>
											</c:choose>	
										</table>
									</td>
									<td style="vertical-align:top;width:25%">
										<table cellspacing="0" cellpadding="0" border="0" width="100%" class="consignee_table">
											<tr>
												<th width="100px;"><fmt:message key="salesOrder.orderNo"/>:</th>
												<td>${orderShipment.salesOrder.orderNo}</td>
											</tr>
											<tr>
												<th><fmt:message key="orderShipment.trackingNo"/>:</th>
												<td>${orderShipment.trackingNo}</td>
											</tr>
											<c:if test="${!orderShipment.isVirtual}">
													<tr>
														<th><fmt:message key="orderShipment.shippingCost"/>:</th>
														<td><common:currencyFormat value="${orderShipment.shippingCost}"/></td>
													</tr>
													<tr>
														<th><fmt:message key="orderShipment.wrapId"/>:</th> 
														<td>
															<c:choose>
																<c:when test="${not empty orderShipment.wrapId}">
																	<fmt:message key="orderShipment.wrapId.yes"/>
																</c:when>
																<c:otherwise>
																	<fmt:message key="orderShipment.wrapId.no"/>
																</c:otherwise>
															</c:choose>
														</td>
													</tr>
													<c:if test="${not empty orderShipment.wrapName}">
														<tr>
															<th><fmt:message key="orderShipment.wrapName"/>:</th>
															<td>${orderShipment.wrapName}</td>
														</tr>
													</c:if>
													<c:if test="${not empty orderShipment.wrapNote}">
														<tr>
															<th><fmt:message key="orderShipment.wrapNote"/>:</th>
															<td>${orderShipment.wrapNote}</td>
														</tr>
													</c:if>
													<c:if test="${not empty orderShipment.wrapCost}">
														<tr>
															<th><fmt:message key="orderShipment.wrapCost"/>:</th>
															<td><common:currencyFormat value="${orderShipment.wrapCost}"/></td>
														</tr>
													</c:if>
											</c:if>	
											
											<tr>
												<th><fmt:message key="orderShipment.createTime"/>:</th>
												<td><fmt:formatDate value="${orderShipment.createTime}" pattern="yyyy-MM-dd HH:mm" />&nbsp;</td>
											</tr>
											
											<tr>
												<th><fmt:message key="orderShipment.createBy" />:</th>
												<td><system:operatorUserName userId="${orderShipment.createBy}"/></td>
											</tr>
											<tr>
												<th><fmt:message key="orderShipment.memo" />:</th>
												<td>${orderShipment.memo}</td>
											</tr>
										</table>
									</td>
									<td style="vertical-align:top;width:30%">
										<%---------------------------------购买的商品 -------------------------%>
										<%@include file="include/orderShipList4Product.jspf" %>
										 
										<%---------------------------------购买的礼券 -------------------------%>
										<%@include file="include/orderShipList4Gc.jspf" %>

										<%---------------------------------兑换的礼品 -------------------------%>
										<%@include file="include/orderShipList4Gift.jspf" %>
										
										<%---------------------------------物流信息 -------------------------%>
										<c:if test="${appConfig.kuaidi100Type != 0 and not empty orderShipment.shippingMethodId}">
											<table border="0" cellspacing="0" cellpadding="0"class="consignee_table" width="100%">
												<tr>
													<th width="60px;"><fmt:message key="orderShipment.kuaidi100QueryTime"/>:</th>
													<td>
														<span id="kuaidi100QueryTime_${orderShipment.documentNo}"><common:datetimeFormat date="${orderShipment.kuaidi100QueryTime}"/></span>
														<input type="button" id="search_${orderShipment.documentNo}" onclick="queryKuaidi100('${orderShipment.documentNo}')" value="<fmt:message key="button.query"/>" class="btn2">
													</td>
												</tr>
												<tr>
													<th><fmt:message key="orderShipment.kuaidi100MessageString"/>:</th>
													<td id="kuaidi100MessageString_${orderShipment.documentNo}"><%@include file="include/orderShipList4Kuaidi100Message.jsp" %></td>
												</tr>
											</table>
										</c:if>
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>	
			</c:forEach>
			<c:if test="${empty orderShipmentList}">
				<tr>
					<td colspan="10" style="text-align:center">
						<fmt:message key="list.empty"/>
					</td>
				</tr>
			</c:if>
		</table>	
		<%@include file="/common/pagingOnly.jsp" %>
	</div>
</form>
<script type="text/javascript">
highlightTableRows("orderShipTable");

$j(document).ready(function () {
	__FMTExtend = {
		orderShipList_pleaseSelectOne:"<fmt:message key="orderShipList.pleaseSelectOne"/>",
		orderShipList_express_ltOne:"<fmt:message key="orderShipList.express.ltOne"/>"
	};
	$j.extend(__FMT, __FMTExtend); 
	autoApplyValidate(document.forms["orderShipListForm"]);
});	

$j.fn.extend({
	loading:function(){
		return this.each(function(){
			$j(this).html('<div class="loading_box"><div class="progress_bar"><img src="'+__ctxPath+'/images/icon/loadingBig.gif"/>loading...</div></div>');			
		});
	}
});

//对已有结果进行排序,ascValue表示升序时对应的值,descValue表示降序时对应的值
function sortField(linkDOM,ascValue,descValue){
	var jThDOM = $j(linkDOM).parent('th');
	if(jThDOM.hasClass("order1")){
		location.replace('${ctxPath}/order/orderShip.html?p-sort='+descValue);
	}else{
		location.replace('${ctxPath}/order/orderShip.html?p-sort='+ascValue);
	}
}
	
//查询快递100
function queryKuaidi100(documentNo){
	$j('#kuaidi100MessageString_'+documentNo).loading().load(__ctxPath+'/order/orderShip.html?decorator=blank&doAction=queryKuaidi100&documentNo='+documentNo);
}

//显示 隐藏全部
function toggleScreenAll(linkDOM){
	if($j(linkDOM).hasClass("expand")){
		$j(linkDOM).removeClass("expand").addClass("shrink");
		$j('span.toggleScreen').each(function(){
			var jTrThis = $j(this).parents('tr:first');
			var jTrFull = jTrThis.next();
			jTrFull.show();
			$j(this).removeClass("expand").addClass("shrink");
		});
	
	}else{
		$j(linkDOM).removeClass("shrink").addClass("expand");
		$j('span.toggleScreen').each(function(){
			var jTrThis = $j(this).parents('tr:first');
			var jTrFull = jTrThis.next();
			jTrFull.hide();
			$j(this).removeClass("shrink").addClass("expand");
		});
	}
}	

//显示 隐藏详细
function toggleScreen(linkDOM){
	var jTrThis = $j(linkDOM).parents('tr:first');
	var jTrFull = jTrThis.next();
	if(jTrFull.is(":hidden")){
		jTrFull.show();
		$j(linkDOM).removeClass("expand").addClass("shrink");
	}else{
		jTrFull.hide();
		$j(linkDOM).removeClass("shrink").addClass("expand");
	}
	
}	
//打印收款单
function printShipList(){
	var paraData=$j(":input[name='multiIds']").serializeArray();
	if(paraData.length>0) {		
		var param = $j.param(paraData);
		var page = __ctxPath+'/order/orderShip.html?doAction=printShipList';
		window.open(page + "&" + param);
	}else{
		alert(__FMT.orderShipList_pleaseSelectOne);	 
	}	
}


//打印快递单
function printExpress(){
	var paraData=$j(":input[name='multiIds']").serializeArray();
	/*if(paraData.length==1) {		
		var param = $j.param(paraData);
		var page = __ctxPath+'/order/orderShip.html?doAction=printOrderExpress';
		window.open(page + "&" + param);
	}else if(paraData.length<1){
		alert(__FMT.orderShipList_pleaseSelectOne);	 
	}else{
		alert(__FMT.orderShipList_express_ltOne);	 
	}*/	

	if(paraData.length<1){
		alert(__FMT.orderShipList_pleaseSelectOne);
	} else {
		var param = $j.param(paraData);
		var page = __ctxPath+'/order/orderShip.html?doAction=printOrderExpress';
		window.open(page + "&" + param);
	} 
}

//保存物流单号
function saveTrackingNo(){
  if(!validateForm(document.forms["orderShipListForm"])){
  	alert(__vaMsg.notPass);
  	return;
  }
  document.forms["orderShipListForm"].action="${ctxPath}/order/orderShip.html?doAction=saveTrackingNo"
  document.forms["orderShipListForm"].method="post"
  document.forms["orderShipListForm"].submit();
}
</script>